home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Pascal Super Library
/
Pascal Super Library (CW International)(1997).bin
/
STRINGS
/
SHLNGST1
/
TEST.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1991-02-19
|
8KB
|
253 lines
program Test;
{to test the ShLngStr unit}
uses
TpDos,
TpCrt,
ShLngStr;
const
Msg : array[1..11] of string[68] =
(('The routines in this unit process strings of characters up to 65517'),
(' char- acters in length. All of the string manipulation features' ),
(' which you are used to having available for use have their analog ' ),
('in this unit.' + ' Every effort has been made to keep all call'),
('ing sequences as intuitive as pos- sible. ' + 'The test sequence '),
('about to begin tests every function and procedure in the unit. Some'),
(' of these tests are implicit; you will not necessarily see them inv'),
('oked in the test, but they will have been invoked at a lower level.'),
( + ' Please notify Madison & Associates at the address, phone nu'),
('mber, or CIS User ID given in the documentation if you have any pro'),
('blems or suggestions regarding ShLngStr.' ));
var
A,
B,
C,
D : LongString;
E,
F,
G : text;
W1 : word;
S1 : string;
procedure Pause;
begin
WriteLn;
Write('Any key to continue...'); if ReadKey = #0 then ;
WriteLn;
end; {Pause}
procedure DC(A : LongString; As : String; B : LongString; Bs : String);
begin
WriteLn;
case lsComp(A, B) of
LESS : WriteLn(As + ' < ' + Bs);
EQUAL : WriteLn(As + ' = ' + Bs);
GREATER : WriteLn(As + ' > ' + Bs);
end; {case}
end; {DC}
procedure WrapLs(C : LongString);
begin
W1 := 0;
repeat
S1 := lsGetNextStrF(C);
if W1 + Length(S1) >= 75 then begin
W1 := Length(S1);
WriteLn;
end
else
inc(W1, Length(S1)+1);
Write(S1, ' ');
until lsLength(C) = 0;
WriteLn;
end; {WrapLs}
begin
WriteLn;
lsWriteLn(Output, lsCharStrF(#205, 75));
WriteLn
(' ShLngStr -- A LongString Processing Unit' );
WriteLn; WriteLn
(' from' );
WriteLn; WriteLn
(' W. G. Madison and Associates, Ltd.' );
WriteLn; WriteLn
(' Copyright 1991 Madison & Associates, Ltd.' );
WriteLn
(' All rights reserved.' );
WriteLn;
assign(F, 'TEST.DAT');
Reset(F);
Assign(G, 'TEST.OUT');
Rewrite(G);
if not lsInit(A, 512) then WriteLn('Bad declaration on A');
if not lsInit(B, 600) then WriteLn('Bad declaration on B');
if not lsInit(C, 2048) then WriteLn('Bad declaration on C');
if not lsInit(D, 2048) then WriteLn('Bad declaration on D');
for W1 := 1 to 11 do
lsTransfer(lsConcatStr2LsF(D, Msg[W1]), D);
WrapLs(D);
lsWriteLn(Output, lsCharStrF(#205, 75));
Pause;
D^.Length := 0;
lsIoff;
WriteLn('Beginning File Copying Test.');
while not eof(F) do begin
lsReadLn(F, A);
if lsIoResult <> 0 then begin
WriteLn('OOPS on reading. ',W1);
Halt;
end;
lsWriteLn(G, A);
if lsIoResult <> 0 then begin
WriteLn('OOPS on writing. ',W1);
Halt;
end;
end; {while}
Close(G);
assign(E, 'COMPARE.BAT');
Rewrite(E);
WriteLn(E, 'COMP TEST.DAT TEST.OUT');
Close(E);
if ExecDos('COMPARE', true, nil) = 0 then ;
Erase(E); {The batch file}
Erase(G); {The output file}
lsIon;
Reset(F);
WriteLn('Beginning RepAll, DelAll test.');
lsReadLn(F, A);
WriteLn(' The original LongString');
lsWriteLn(Output, A);
lsRepAllStr(A, 'abc', '12345', C);
lsTransfer(lsRepAllStrF(A, 'abc', '12345'), B);
WriteLn(Output, ^M^J'''abc'' replaced by ''12345''.');
lsWriteLn(Output, B);
DC(C, 'lsRepAllStr(A, ''abc'', ''12345'', C)',
B, 'lsRepAllStrF(A, ''abc'', ''12345'')');
Pause;
lsRepAllStrUC(A, 'abc', '12345', C);
WriteLn(Output, ^M^J'Case insensitive replacement of ''abc'' by ''12345''.');
lsWriteLn(Output, C);
DC(C, 'lsRepAllStrUC(A, ''abc'', ''12345'', C)',
lsRepAllStrUCF(A, 'abc', '12345'), 'lsRepAllStrUCF(A, ''abc'', ''12345'')');
Pause;
lsDelAllStr(A, 'abc', B);
WriteLn(Output, ^M^J'''abc'' deleted.');
lsWriteLn(Output, B);
DC(B, 'lsDelAllStr(A, ''abc'', B)', lsDelAllStrF(A, 'abc'),
'lsDelAllStrF(A, ''abc'')');
DC(B, 'lsDelAllStr(A, ''abc'', B)', lsDelAllF(A, lsStr2LongStringF('abc')),
'lsDelAllF(A, lsStr2LongStringF(''abc''))');
Pause;
WriteLn(Output, ^M^J'Centered in a field 560 wide.');
lsCenter(A, 560, B);
lsWriteLn(Output, B);
DC(B, 'lsCenter(A, 560, B)', lsCenterF(A, 560), 'lsCenterF(A, 560)');
DC(B, 'lsCenter(A, 560, B)',
lsCenterChF(A, ' ', 560), 'lsCenterChF(A, '' '', 560)');
W1 := 560 - ((560 - lsLength(A)) shr 1);
lsPad(lsLeftPadF(A, W1), 560, C);
DC(B, 'lsCenter(A, 560, B)',
C, ^M^J' lsPad(lsLeftPadF(A, 560 - ((560 - lsLength(A)) shr 1)), 560, C)');
Pause;
WriteLn(Output, ^M^J'Restore by trimming, padding.');
lsTrimTrail(lsTrimLeadF(B), C);
lsTrim(B, B);
lsLeftPad(B, lsLength(A), B);
lsLeftPad(C, lsLength(A), C);
lsWriteLn(Output, B);
DC(B, 'lsTrim(B, B); lsLeftPad(B, lsLength(A), B)',
lsLeftPadF(lsTrimF(B), lsLength(A)),
'lsLeftPadF(lsTrimF(B), lsLength(A))');
DC(B, 'lsTrim(B, B); lsLeftPad(B, lsLength(A), B)',
C, ^M^J' lsTrimTrail(lsTrimLeadF(B), C); lsLeftPad(C, lsLength(A), C)');
Pause;
WriteLn(^M^J'Upcase test');
lsWriteLn(Output, lsUpcaseF(B));
lsUpcase(B, C);
DC(lsUpcaseF(B), 'lsUpcaseF(B)', C, 'lsUpcase(B, C)');
Pause;
WriteLn(^M^J'Locase test');
lsWriteLn(Output, lsLocaseF(B));
lsLocase(B, C);
DC(lsLocaseF(B), 'lsLocaseF(B)', C, 'lsLocase(B, C)');
Pause;
WriteLn(^M^J'Copy test');
WriteLn('Copy first upper case alphabet from the following string.');
lsWriteLn(Output, A);
lsCopy(A, lsPosStr('A', A), 26, B);
WriteLn;
lsWriteLn(Output, lsCopyF(A, lsPosStr('A', A), 26));
DC(B, 'lsCopy(A, lsPosStr(''A'', A), 26, B)',
lsCopyF(A, lsPosStr('A', A), 26),
'lsCopyF(A, lsPosStr(''A'', A), 26)');
Pause;
WriteLn(^M^J'Insert test');
WriteLn('Insert upper case alphabet preceeding ''k'' in original LongString.');
lsWriteLn(Output, A);
WriteLn;
lsWriteLn(Output, B);
WriteLn;
lsWriteLn(Output, lsInsertStrF(A, lsLongString2Str(B), lsPosStr('k', A)));
lsInsertStr(A, lsLongString2Str(B), lsPosStr('k', A), C);
DC(C, 'lsInsertStr(A, lsLongString2Str(B), lsPosStr(''k'', A), C)',
lsInsertStrF(A, lsLongString2Str(B), lsPosStr('k', A)),
^M^J' lsInsertStrF(A, lsLongString2Str(B), lsPosStr(''k'', A))');
Pause;
WriteLn(^M^J'Delete test');
WriteLn('Delete the inserted upper case alphabet from the above.');
WriteLn(' This should return the LongString to its original form.');
lsWriteLn(Output, lsDeleteF(C, lsPosStr('A', C), 26));
DC(A, 'A', lsDeleteF(C, lsPosStr('A', C), 26),
'lsDeleteF(C, lsPosStr(''A'', C), 26)');
Pause;
{Prepare for concatenation, GetNext tests}
Reset(F);
repeat
lsReadLn(F, A);
until lsPosStrUC('WHEN', A) <> 0;
lsTransfer(A, C);
lsTransfer(A, D);
repeat
lsReadLn(F, A);
lsConcat(C, A, C);
lsTransfer(lsConcatF(D, A), D);
until eof(F);
WriteLn(^M^J'Concatenation test');
lsWriteLn(Output, C);
DC(C, 'lsConcat(C, A, C)', D, 'lsTransfer(lsConcatF(D, A), D)');
Pause;
WriteLn(^M^J'GetNext test, doing a word wrap on the above.');
WrapLs(C);
Close(F);
WriteLn(^M^J'I/O Error Handling test.');
lsIoff;
Assign(E, 'FOO.BAZ');
WriteLn
('The next line displayed should be ''104 (File not open for input)''');
lsReadLn(E, A);
WriteLn(lsIoResult,' (File not open for input)');
WriteLn
('The next event should be a runtime error and program termination.');
lsReadLn(E, A);
lsReadLn(E, A);
lsIon;
end.